package cn.deu.xunwu;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.dzu.dao.XunwuDao;

/**
 * Servlet implementation class delete
 */
@WebServlet("/delete")
public class delete extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public delete() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id  = request.getParameter("id");
		int userid = Integer.parseInt(id);	
		
		 ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
		   XunwuDao xunwu=(XunwuDao)applicationContext.getBean("XunwuDao");	
		   int i=  xunwu.delete(userid);
		   if(i==1) {
			   request.getRequestDispatcher("/select").forward(request, response);
		   }else {
			   response.setContentType("text/html;charset=UTF-8");
			   PrintWriter out=response.getWriter();	
			   out.print("<script>alert('删除信息错误');</script>");
		   }
	}

}
